package com.ibeetl.admin.core.service;

import com.ibeetl.admin.core.dao.FiDataTransDetailDao;
import com.ibeetl.admin.core.entity.CoreSearch;
import com.ibeetl.admin.core.entity.DataCheckRules;
import com.ibeetl.admin.core.entity.FiDataTransDetail;
import com.ibeetl.admin.core.entity.mfiDataTransDetail;
import com.ibeetl.admin.core.util.JDBCUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

@Service
@Transactional
public class FiDataTransDetailService  {
	@Autowired
	FiDataTransDetailDao fiDataTransDetailDAO;

	public List<DataCheckRules> queryVersionRules(CoreSearch search) {
		return fiDataTransDetailDAO.queryVersionRules(search);
	}

	public List<FiDataTransDetail> queryData(String sql) {
		JdbcTemplate template = new JdbcTemplate(JDBCUtils.getDataSource());
		List<FiDataTransDetail> fiDataTransDetails = template.query(sql,new Object[]{},new BeanPropertyRowMapper<FiDataTransDetail>(FiDataTransDetail.class));
		return fiDataTransDetails;
//		return  fiDataTransDetailDAO.queryData(sql);
	}

	public void saveDataTransDetail(FiDataTransDetail dataTransDetail) {
		fiDataTransDetailDAO.insert(dataTransDetail);
	}

	public void deleteFromFiDataTransDetail(CoreSearch search) {
		fiDataTransDetailDAO.deleteFromFiDataTransDetail(search);
	}

	public List<FiDataTransDetail> getFiDataTransDetailDatasOfMoney(CoreSearch search) {
		return fiDataTransDetailDAO.getFiDataTransDetailDatasOfMoney(search);
	}

	public List<FiDataTransDetail> getFiDataTransDetailDatasOfItem(CoreSearch search) {
		return fiDataTransDetailDAO.getFiDataTransDetailDatasOfItem(search);
	}

	public String getDate(String dateRange, String returnType){
		String[] dateStr = null;
		String date = null;
		dateStr=dateRange.split("至");
		if(returnType.equals("0")){
			date = dateStr[0].trim();
		}else{
			date = dateStr[1].trim();
		}
		return date;
	}

	public List<mfiDataTransDetail> queryItemData(String sql) {
		return fiDataTransDetailDAO.queryItemData(sql);
	}

	public FiDataTransDetail getFiDataTransDetail( FiDataTransDetail fiDataTransDetail){
		return fiDataTransDetailDAO.getFiDataTransDetail(fiDataTransDetail);
	}

	public List<DataCheckRules> queryCheckRules(String versionNo){
		return fiDataTransDetailDAO.queryCheckRules(versionNo);
	}

}
